using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class JobSeekers_action : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
        if (PreviousPage == null)
        {
            this.lblHeader.Text = "Sorry, you are doing nothing";
        }
        else
        {
            HiddenField1.Value="";
            string jsemail = Convert.ToString(Session["jsemail"]);
            SQLServerProviders cls = new SQLServerProviders();
            Page page = PreviousPage;
            
            HiddenField hiddenField = (HiddenField)page.FindControl("hdfAction");
            TextBox textBox1,textBox2,textBox3,textBox4 ;
            switch (hiddenField.Value)
            {
                case "CPWD":
                    this.lblHeader.Text = "Change password";
                    textBox1 =(TextBox)page.FindControl("txtOldPassword");
                    textBox2 =(TextBox)page.FindControl("txtPassword");
                    if(cls.ChangePassword(jsemail,textBox1.Text, textBox2.Text))
                    {
                        Literal1.Text ="You have changed password successful. It will be effected on next time";
                        HiddenField1.Value="myaccount.aspx";
                    }
                    else
                    {
                        Literal1.Text = "Sorry, your password is not correct."
                        + cls.ErrorMessage;
                        HiddenField1.Value = "changepassword.aspx";
                    }
                    break;
                case "FGPWD":
                    this.lblHeader.Text = "Forgot password";
                    textBox1 = (TextBox)page.FindControl("txtEmail");
                    textBox2 = (TextBox)page.FindControl("txtFirstName");
                    textBox3 = (TextBox)page.FindControl("txtLastName");
                    textBox4 = (TextBox)page.FindControl("txtDOB");
                    string password= 
                    cls.ForgotPassword(
                    textBox1.Text, textBox2.Text+ " " + textBox3.Text, textBox4.Text);
                    if(cls.ErrorMessage=="" && password!="")
                    {
                        MailClass mailClass = new MailClass();
                        mailClass.SendMail(textBox1.Text, 
                        "Forgot password", "Here is your new password: " + password);
                        Literal1.Text = "Send password to your email successful.";
                        HiddenField1.Value = "login.aspx";
                    }
                    else
                    {
                        Literal1.Text = "Sorry, can not send password to you. "
                        + cls.ErrorMessage;
                        HiddenField1.Value = "forgotpassword.aspx";
                    }
                    break;
            }
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if(HiddenField1.Value!="")
            Response.Redirect(HiddenField1.Value);
    }
}
